//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by zzx on 2017/7/23.
//  Copyright © 2017年 zzx. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(title: String , imageName:String? = nil , target: Any?, action: Selector) {
        
        let button = UIButton()
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        if imageName != nil {
            
            button.setImage(UIImage(named: imageName!), for: .normal)
            
        }
        
        
        button.setTitle(title, for: .normal)
        
        //设置不同状态下的文字
        button.setTitleColor(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1), for: .normal)
        
        button.setTitleColor(#colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1), for: .highlighted)
        
        //设置文字大小
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        //自适应
        button.sizeToFit()
        
        self.init(customView: button)
        
        
    }
    
    
    




}
